package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.vo.JobApplyWithJobVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JobApply;
import com.ruoyi.business.service.IJobApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位投递Controller
 * 
 * @author asher
 * @date 2021-11-22
 */
@RestController
@RequestMapping("/business/job_apply")
public class JobApplyController extends BaseController
{
    @Autowired
    private IJobApplyService jobApplyService;

    /**
     * 查询岗位投递列表
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(JobApply jobApply)
    {
        startPage();
        List<JobApplyWithJobVO> list = jobApplyService.selectJobApplyWithJobList(jobApply);
        return getDataTable(list);
    }

    /**
     * 导出岗位投递列表
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:export')")
    @Log(title = "岗位投递", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(JobApply jobApply)
    {
        List<JobApply> list = jobApplyService.selectJobApplyList(jobApply);
        ExcelUtil<JobApply> util = new ExcelUtil<JobApply>(JobApply.class);
        return util.exportExcel(list, "岗位投递数据");
    }

    /**
     * 获取岗位投递详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return AjaxResult.success(jobApplyService.selectJobApplyByApplyId(applyId));
    }

    /**
     * 新增岗位投递
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:add')")
    @Log(title = "岗位投递", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JobApply jobApply)
    {
        return toAjax(jobApplyService.insertJobApply(jobApply));
    }

    /**
     * 修改岗位投递
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:edit')")
    @Log(title = "岗位投递", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JobApply jobApply)
    {
        return toAjax(jobApplyService.updateJobApply(jobApply));
    }

    /**
     * 删除岗位投递
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:remove')")
    @Log(title = "岗位投递", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(jobApplyService.deleteJobApplyByApplyIds(applyIds));
    }

    /**
     * 查询岗位投递列表
     */
    @PreAuthorize("@ss.hasPermi('business:job_apply:list')")
    @GetMapping("/withJobList")
    public TableDataInfo withJobList(JobApply jobApply)
    {
        startPage();
        List<JobApplyWithJobVO> list = jobApplyService.selectJobApplyWithJobList(jobApply);
        return getDataTable(list);
    }
}
